home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / match-nshell.hqx / match / Examples next >
Encoding:
Text File  |  1994-11-06  |  1.4 KB  |  47 lines

  1. Note: If you are unfamiliar with the shell wildcards used by the "match" command, you may wish to review section 06, "Wildcards", of the nShell User's Guide.
  2.  
  3. Examples:
  4.  
  5. A simple example of a search would be a search for copyright notices:
  6.  
  7. % match * -p Copyright
  8.  
  9. The thing is, not everyone may have remembered to capitalize the word copyright.  There are two solutions.  First of all, we could simplify the search to the last part of the word, relying on the fact that few words end with "opyright":
  10.  
  11. % match * -p opyright
  12.  
  13. Secondly, we could use a "[]" clause to select either small or large "C":
  14.  
  15. % match * -p '[Cc]opyright'
  16.  
  17. When the pattern contains wildcards, it's best to enclose it within single quotes.
  18.  
  19. In these examples a "*" wildcard is used to search the current directory.  We might use an extended path to search other places.  The following command would search all ".h" files in the "include" folder for the pattern "printf":
  20.  
  21. % match :includes:*.h -p printf
  22.  
  23. The following script makes use of the "sfget" command to search a series of directories.  The script continues until the user selects "cancel" in the "sfget" dialog:
  24.  
  25. #
  26. # script - search_folders
  27.  
  28. if .ne. $# 2 then
  29.  echo "Usage: search_folders pattern"
  30.  exit -1
  31. endif
  32.  
  33. while sfget -p "Select a folder to search" folder
  34.  do
  35.   if cd "$folder"
  36.    then
  37.     echo " "
  38.     echo "Searching $folder ..."
  39.     echo " "
  40.     match * -p "$1"
  41.    endif
  42. done
  43.  
  44. #
  45. # end - search_folders